let angle = 0
let noiseLevel = 0.01
let speed = 0.01
function setup() {
    bicycle = new Bicicle(windowWidth / 2 - 100, windowHeight / 2, 100)

    createCanvas(windowWidth, windowHeight)
}

function draw() {
    background(220);

    bicycle.draw()
}

class Bicicle {
    constructor(x, y, dia, speed = 0.01) {


        this.x = x
        this.y = y
        this.dia = dia
        this.speed = speed
        this.angle = random(0, 100)
    }

    drawWheel(x, y, dia) {
        push()

        translate(x, y)//原点移到x，y
        rotate(this.angle)//初始旋转
        noFill()//画轮子
        circle(0, 0, dia)//内胎
        circle(0, 0, dia * 1.1)//外轮
        line(0, 0, dia / 2 * cos(PI / 8 * 1), dia / 2 * sin(PI / 8 * 1))//辐条
        fill(78)//轮轴
        circle(0, 0, dia * 0.1)//轮轴
        this.angle += this.speed//转动
        pop()
    }

    drawFrame(x, y) {
        const rearX = x
        const rearY = y
        push()
        translate(x, y)//    原点移到x，y
        noFill()//画车架
        const bottomX = 90
        const bottomY = 12
        const topX = 70
        const topY = -70
        const frontX = 170
        const frontY = -70
        const handleX = frontX - 12
        const handleY = frontY - 12 * 7 / 3
        const endupdown = 13
        triangle(0, 0, bottomX, bottomY, topX, topY)//车架左半边
        triangle(frontX, frontY, bottomX, bottomY, topX, topY)//车架右半边
        circle(90, 12, 20)//牙盘
        line(200, 0, handleX, handleY)//前叉
        line(handleX + endupdown, handleY + endupdown, handleX - endupdown, handleY - endupdown)
        line(topX, topY, topX - 5, topY - 5 * (bottomY - topY) / (bottomX - topX))
        translate(topX - 5, topY - 5 * (bottomY - topY) / (bottomX - topX))
        strokeWeight(5)
        line(-5, 0, 5, 0)
        strokeWeight(1)


    }
    draw() {

        let a = 20 * noise(frameCount * 0.01 + 10)
        let shakeAmp = floor(this.a)

        this.drawWheel(this.x, this.y, this.dia)
        this.drawWheel(this.x + 200, this.y, this.dia)
        this.drawFrame(this.x, this.y)
    }
}

class frame {
    constructor(x, y, dia) {
        this.x = x
        this.y = y
        this.dia = dia
    }
}